<%@page contentType="text/html" pageEncoding="UTF-8" import="org.bsscheduler.*"%>

<%
String firstName = request.getParameter("firstname");
String lastName = request.getParameter("lastname");
String email = request.getParameter("email");
String password1 = request.getParameter("password1");
String password2 = request.getParameter("password2");

// If any fields are net set, go to registration page
if (firstName == null || lastName == null || email == null ||
        password1 == null || password2 == null) { %>
<jsp:forward page="register.jsp" />
<% }

// If the username exists, go to registration page
if (UsersDB.userExists(email)) { %>
<jsp:forward page="register.jsp?err=userexists" />
<% }

// If two password fields don't match, go to registration page
if (!password1.equals(password2)) { %>
<jsp:forward page="register.jsp?err=pwdmatch" />
<% }

// Create new user
UsersDB.createUser(email, password1, firstName, lastName);

%>
<jsp:forward page="index.jsp?action=created" />
